package com.pxst.bank.mapper;

import java.math.BigDecimal;
import java.util.List;

import icu.mhb.mybatisplus.plugln.base.mapper.JoinBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pxst.bank.entity.SysBankCardEntity;

/** 
* @author yangxy
* @version 创建时间：2023年9月7日 下午5:24:41 
*/
@Mapper
public interface SysBankCardMapper extends JoinBaseMapper<SysBankCardEntity> {
	/**
	 * 获取银行卡
	* @author yangxy
	* @version 创建时间：2023年9月12日 下午3:10:44 
	* @param txnMode 交易类型
	* @param currency 币种
	* @param orderAmount 金额
	* @param bankCode 银行编码
	* @return
	 */
	@Select(value="SELECT "
			+ "	bankCard.*  "
			+ "FROM "
			+ "	sys_bank_card bankCard "
			+ "	LEFT JOIN sys_available_bank availableBank ON bankCard.available_bank_id = availableBank.id "
			+ "	LEFT JOIN sys_bank_card_flow bankCardFlow ON bankCardFlow.bank_card_id = bankCard.id  "
			+ "WHERE "
			+ "	EXISTS ( SELECT 1 FROM sys_merchant_available_bank merchantAvailableBank  "
			+ "		WHERE merchantAvailableBank.available_bank_id = bankCard.id  "
			+ "		AND merchantAvailableBank.is_enabled = 1  "
			+ "		AND merchantAvailableBank.trade_type = #{txnMode} "
			+ "	)  "
			+ "	AND bankCard.type = #{txnMode} "
			+ "	AND bankCard.currency = #{currency} "
			+ "	AND bankCard.day_deposit_max - bankCardFlow.total_day_credit >= #{orderAmount} "
			+ "ORDER BY "
			+ "	availableBank.bank_code = #{bankCode} DESC, "
			+ "	bankCardFlow.capacity ASC")
	List<SysBankCardEntity> getBankCardList(@Param("txnMode") int txnMode,@Param("currency") String currency,
			@Param("orderAmount") BigDecimal orderAmount,@Param("bankCode") String bankCode);
}
